package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.SysHz;
import com.jy.wms.pojo.WmsEstimatedArrivalOrder;
import com.jy.wms.pojo.WmsShelves;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsFailedStorage;
import com.jy.wms.service.WmsFailedStorageService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.List;
import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsFailedStorageController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author LH
 * @Date Tue Jan 23 09:31:28 GMT+08:00 2018
 */
@RestController
@RequestMapping("/wmsfailedstorage")
@Api(value = "/wmsfailedstorage", description = "不合格品处理操作（出库）")
public class  WmsFailedStorageController extends BaseController<WmsFailedStorageService,WmsFailedStorage> {

    /**
     * 上架管理 新增上架信息
     * @param list
     * @param session
     * @return
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "不合格品出库 确认出库",response = JSONObject.class, notes = "确认出库")
    public @ResponseBody JSONObject addWmsLibraryPosition(@RequestBody List<WmsShelves> list, HttpSession session) {
        JSONObject json = getJSONObject();
        try {
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            String ckid=String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库编号
            String hzid=null;//取当前货主编号
            List<SysHz> hz= (List<SysHz>) session.getAttribute(BaseSessionInfo.SessionConsignor);
            if(hz.size()>0){
                hzid=hz.get(0).getHzid();
            }
            baseService.confirm(list,userinfo.getUser().getName(),ckid);
            json = SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"确认出库信息成功","", "");
        }catch (ServiceException e){
            e.printStackTrace();
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.warning.toString(),"确认出库信息失败",e.getMessage(),"");
        }catch (SucessException e){
            e.printStackTrace();
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.warning.toString(),"确认出库信息成功",e.getMessage(),"");
        }catch (Exception e) {
            e.printStackTrace();
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"确认出库信息失败","确认出库信息失败","");
        }
        return json;
    }





}
